#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
 #include <arpa/inet.h>
#define Port 1235
#define server_ip "192.168.0.110"
char recive_buff[1024];
int main(int argc, char const *argv[])
{
    /* code */
    int socket_fd;
    int server_fd;
    struct sockaddr_in server_addr;
    /* 创建socket 套接字 */
    socket_fd = socket(AF_INET,SOCK_STREAM,0);
    if (socket_fd==-1)
    {
        /* code */
        perror("socket\n");
        exit(-1);
    }
    /* 连接服务器 */
    memset(&server_addr,0,sizeof(struct sockaddr_in));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = (inet_addr(server_ip));//把字符串形式的 IP地址转换为 uint32类型的 IP地址数据 b并转换为网络字节序
    server_addr.sin_port = htons(Port);
    server_fd = connect(socket_fd,(struct sockaddr *)&server_addr,sizeof(struct sockaddr_in));
    if (server_fd==-1)
    {
        /* code */
        perror("connect\n");
        close(socket_fd);
        close(server_fd);
        exit(-1);
    }
    printf("connect success\n");
    while (1)
    {
        /* code */
        recv(socket_fd,recive_buff,1024,0);
        printf("\n");
        printf("recive data %s\n",recive_buff);
    }
    
    return 0;
}
